<template>
	<!-- 注销 wwl -->
	<page  ref='page'>
		<view class="page">
			<view class="row">
				<view class="left">
					手机号码
				</view>
				<view class="right">
					<text>{{userInfo.phone}}</text>
				</view>
			</view>
			<!-- <view class="row">
				<view class="left">
					验证码
				</view>
				<view class="right right2">
					<view class="input">
						<input type="text" v-model="code" maxlength="6" />
					</view>
					<button @click='getCode()' class="btn">{{codeText}}</button>
				</view>
			</view> -->
			<button class="bottom_box" @click="onSave()">
				申请注销
			</button>
		</view>
	</page>
</template>

<script>
	import { setUserDelete } from './static/api.js'
	export default {
		data() {
			return {
				code: null,
				codeText: '获取验证码',
				codeLoading: false,
				timeFUN: null,
				userInfo:null,
			}
		},
		methods: {
			async getCode() {
				if (this.codeLoading) return
				this.codeLoading = true
				this.codeText = '发送中'
				let timeNum = 59
				this.timeFUN = setInterval(() => {
					if (timeNum === 0) {
						this.codeLoading = false
						this.codeText = '获取验证码'
						clearInterval(this.timeFUN)
					} else {
						this.codeText = timeNum + 's'
						timeNum = timeNum - 1
					}
				}, 1000)
			},
			onSave() {
				if(this.loading) return 
				// if(!this.code) return uni.showToast({title: '请输验证码',icon: 'none'})
				// if(!(/^([0-9]{4,6})$/.test(this.code))){
				// 	return uni.showToast({
				// 		title: '请输正确的验证码',
				// 		icon: 'none'
				// 	});
				// }
				uni.showModal({
					title: '提示',
					content: '是否确认注销用户？',
					success:async (res)=>{
						if (res.confirm) {
							this.loading = true
							try{
								var res2 = await setUserDelete(this.code)
								this.$store.commit('setToken',null)
								// uni.removeStorageSync('TZ_token')
								this.$store.commit('setUser',null)
								// uni.removeStorageSync('TZ_userInfo')
								this.$store.commit('setInvitationCode', null)
								// uni.removeStorageSync('TZ_invitation_code')
								this.$store.commit('setInvitationCode', null)
								// this.$store.commit('setCurrentArea',null)
								this.$store.commit('setAddressSelect',null)
								this.$store.commit('setNewUser',2)
								this.$store.commit('setCurrentAddressList','')
								this.$store.commit('setCityData',null)
								this.$store.commit('setIsOpenSetting',0)
								this.$store.commit('setIsOpenSettingshow',0)
								uni.showToast({
									title:'注销成功',icon:'none'
								})
								setTimeout(()=>{
									this.loading = false
									uni.reLaunch({
										url:'/pages/index/index'
									})
								},1500)
							}catch{
								this.loading = false
							}
							
					  }
					}
				})
			}
		},
		onLoad(params) {
			this.userInfo = this.$store.state.userInfo
		},
	}
</script>

<style lang="scss" scoped>
	.row {
		width: 100%;
		padding: 32rpx 36rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 32rpx;
		color: #26252B;
		line-height: 44rpx;
		background-color: #fff;

		.right {
			width: calc(100% - 5em);
			text-align: right;
		}

		.btn {
			width: 200rpx;
			font-size: 32rpx;
			color: #FE7A1F;
			margin: 0;
		}

		.right2 {
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.input {
			width: calc(100% - 230rpx);
			text-align: right;
		}
	}

	.bottom_box {
		height: 104rpx;
		line-height: 104rpx;
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		background-color: $theme;
		color: #fff;
		font-size: 32rpx;
	}

	button[loading]::before {
		align-self: center
	}

	button {
		display: flex;
		justify-content: center;
		align-item: center;
		padding: 0;
		border-radius: 0;
		background-color: #fff;
	}

	button::after {
		border: none;
	}
</style>
